<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>laravist vuejs2</title>
</head>
<body>
<div id="app">
    {{message}}
    <div><input type="text" v-model="message" /></div>
    <div>
        <ul>
            <li v-for="(m,index) in msg">
                {{m.title}}
                <span v-on:click="deleteTodo(index)">删除</span>
            </li>
        </ul>
    </div>
    <form v-on:submit.prevent="addTodo(newTodo)">
        <input type="text" v-model="newTodo.title">
        <input type="submit" value="提交">
    </form>
</div>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!',
            msg:[
                {id:1,title:'learn vue'}
            ],
            newTodo:{id:null,title:''}
        },
        methods:{
            addTodo:function (newTodo) {
                this.msg.push(newTodo);
                this.newTodo = {id:null,title:''};
            },
            deleteTodo:function (index) {
                this.msg.splice(index,1);
            }
        }
    });
</script>
</body>
</html>